<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once('c_base.php');

class Book extends C_Base {

	/**
	 * BookAPI Page for this controller.
	 * map to /book/<method_name>/<call>
	 */
	 
    var $folder = 'accountbook/';
	var $err_not_found = 'Method is not Found.';
	
    /*
     * 用户相关的API接口
     */        
    public function user(){
        
        $call = $this->uri->segment(3,0);

        if($call){
            $this->load->library($this->folder.'CUser',$_POST);
            if(method_exists($this->cuser, $call)){
                call_user_func(array($this->cuser,$call));                    
                return;
            }                
        }

        $this->error($this->err_not_found);            
    }	
    
    /*
     * 账本数据相关的API接口
     */        
    public function data(){

        $call = $this->uri->segment(3,0);

        if($call){
            $this->load->library($this->folder.'CBook',$_POST);
            if(method_exists($this->cbook, $call)){
                call_user_func(array($this->cbook,$call));                    
                return;
            }                
        }

        $this->error($this->err_not_found);
    }
    
    protected function error($msg){
        $res = array(
            'MessageId'	=> '',
            'ACK' => 0,
            'Text'	=> $msg
        );
        echo json_encode($res);
        exit;
    }	    
}